<?php
/**
 * Created by PhpStorm.
 * User: lenvo
 * Date: 2018/7/8
 * Time: 17:28
 */

namespace app\merchant\controller;


use think\Request;

class Merchant extends Basic{
    protected $mer_service = null;
    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this->mer_service = new \app\merchant\service\Merchant();
    }

    public function index() {
        $ret = $this->mer_service->get_mer_info($this->merchant);
        $service = new \app\merchant\service\Area();
        $area_ret = $service->getChild(0);
        if($area_ret->getCode() == \app\merchant\define\Merchant::$Code_Mer_Error) {
            $this->assign("area",[]);
        }else {
            $area = $area_ret->getData("area");
            $this->assign("area",$area);
        }
        $this->assign("mer_id",$this->merchant['id']);

        if($ret->getCode() == \app\merchant\define\Merchant::$Code_Mer_Error) {
            return $this->fetch();
        }
        $info = $ret->getData("info");
        $this->assign("info",$info);
        return $this->fetch();
    }

    public function edit_info() {
        $_form = input('');
        $ret = $this->mer_service->edit_mer_info($_form);
        if($ret->getCode() == \app\merchant\define\Merchant::$Code_Mer_Error) {
            return $this->ret->setCode(1)->setMsg($ret->getMsg())->toJson();
        }
        return $this->ret->setCode(0)->setMsg($ret->getMsg())->setReload()->toJson();
    }
    public function cert() {
        $ret = $this->mer_service->get_mer_cert($this->merchant);
        if($ret->getCode() == \app\merchant\define\Merchant::$Code_Mer_Error) {
            return $this->fetch();
        }
        $cert = $ret->getData("cert");
        $this->assign("cert",$cert);
        return $this->fetch();
    }

    public function edit_cert() {
        $_form = input('');
        $ret = $this->mer_service->edit_mer_cert($_form,$this->merchant['id']);
        if($ret->getCode() == \app\merchant\define\Merchant::$Code_Mer_Error) {
            return $this->ret->setCode(1)->setMsg($ret->getMsg())->toJson();
        }
        return $this->ret->setCode(0)->setMsg($ret->getMsg())->setReload()->toJson();
    }

    public function deposit() {
        $ret = $this->mer_service->get_mer_deposit($this->merchant);
        if($ret->getCode() == \app\merchant\define\Merchant::$Code_Mer_Error) {
            return $this->fetch();
        }
        $deposit = $ret->getData("deposit");
        $this->assign("deposit",$deposit);
        return $this->fetch();
    }

    public function store() {
        $ret = $this->mer_service->get_mer_store($this->merchant);
        if($ret->getCode() == \app\merchant\define\Merchant::$Code_Mer_Error) {
            return $this->fetch();
        }
        $store = $ret->getData("store");
        $this->assign("store",$store);
        return $this->fetch();
    }

    public function edit_store() {
        $_form = input('');
        $ret = $this->mer_service->edit_mer_store($_form,$this->merchant['id']);
        if($ret->getCode() == \app\merchant\define\Merchant::$Code_Mer_Error) {
            return $this->ret->setCode(1)->setMsg($ret->getMsg())->toJson();
        }
        return $this->ret->setCode(0)->setMsg($ret->getMsg())->setReload()->toJson();
    }
}